﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
/// <summary>
/// Summary description for OTODATAACCESS
/// </summary>
public static class OTO_DATAACCESS
{
    private static string sp_Name = "sp_XE";
    public static void ExcuteQueryString(string ACTION, OTO_ENTITY oto)
    {
        SqlCommand com = new SqlCommand();
        DATABASE_CONTROL csdl = new DATABASE_CONTROL();
        try
        {

            com.Connection = csdl.CheckConnect();
            com.Parameters.AddWithValue("ACTION", ACTION);
            if (oto != null)
            {
                com.Parameters.AddWithValue("MAXE", oto.MAXE);
                com.Parameters.AddWithValue("TENXE", oto.TENXE);
                com.Parameters.AddWithValue("MAHANG", oto.MAHANG);
                com.Parameters.AddWithValue("XUATXU", oto.XUATXU);
                com.Parameters.AddWithValue("MAUSAC", oto.MAUSAC);
                com.Parameters.AddWithValue("NHIENLIEU", oto.NHIENLIEU);
                com.Parameters.AddWithValue("HINH", oto.HINH);
            }
            com.CommandType = CommandType.StoredProcedure;
            com.CommandText = sp_Name;
            if (com.Connection.State == ConnectionState.Closed)
            {
                com.Connection.Open();
            }
            com.ExecuteNonQuery();
        }
        catch( Exception ex)
        { 
            throw ex;
        }
        finally
        {
            com.Connection.Close();
        }
    }
    public static DataSet GETDATATABLE(string ACTION, OTO_ENTITY oto)
    {
        SqlCommand com = new SqlCommand();
        DATABASE_CONTROL csdl = new DATABASE_CONTROL();
        DataSet ds;
        try
        {

            com.Connection = csdl.CheckConnect();
            com.Parameters.AddWithValue("ACTION", ACTION);
            if (oto != null)
            {
                com.Parameters.AddWithValue("MAXE", oto.MAXE);
                com.Parameters.AddWithValue("TENXE", oto.TENXE);
                com.Parameters.AddWithValue("MAHANG", oto.MAHANG);
                com.Parameters.AddWithValue("XUATXU", oto.XUATXU);
                com.Parameters.AddWithValue("MAUSAC", oto.MAUSAC);
                com.Parameters.AddWithValue("NHIENLIEU", oto.NHIENLIEU);

            }
            com.CommandType = CommandType.StoredProcedure;
            com.CommandText = sp_Name;
            if (com.Connection.State == ConnectionState.Closed)
            {
                com.Connection.Open();
            }
            ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(com);
            da.Fill(ds);
            return ds;
        }
        catch (Exception ex)
        {
            return new DataSet();
            throw ex;
        }
        finally
        {
            com.Connection.Close();
        }
    }
    public static DataSet GETDATATABLENONE(string ACTION)
    {
        SqlCommand com = new SqlCommand();
        DATABASE_CONTROL csdl = new DATABASE_CONTROL();
        DataSet ds;
        try
        {

            com.Connection = csdl.CheckConnect();
            com.Parameters.AddWithValue("ACTION", ACTION);          
            com.CommandType = CommandType.StoredProcedure;
            com.CommandText = sp_Name;
            if (com.Connection.State == ConnectionState.Closed)
            {
                com.Connection.Open();
            }
            ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(com);
            da.Fill(ds);
            return ds;
        }
        catch (Exception ex)
        {
            return new DataSet();
            throw ex;
        }
        finally
        {
            com.Connection.Close();
        }
    }
    //search
    public static DataSet GETDATATABLESER(string ACTION, OTO_ENTITY oto)
    {
        SqlCommand com = new SqlCommand();
        DATABASE_CONTROL csdl = new DATABASE_CONTROL();
        DataSet ds;
        try
        {

            com.Connection = csdl.CheckConnect();
            com.Parameters.AddWithValue("ACTION", ACTION);
            if (oto != null)
            {
                com.Parameters.AddWithValue("MAXE", oto.MAXE);
                com.Parameters.AddWithValue("TENXE", oto.TENXE);
                com.Parameters.AddWithValue("MAHANG", oto.MAHANG);
                com.Parameters.AddWithValue("XUATXU", oto.XUATXU);
                com.Parameters.AddWithValue("MAUSAC", oto.MAUSAC);
                com.Parameters.AddWithValue("NHIENLIEU", oto.NHIENLIEU);

            }
            com.CommandType = CommandType.StoredProcedure;
            com.CommandText = "WEB_SEARCHXE";
            if (com.Connection.State == ConnectionState.Closed)
            {
                com.Connection.Open();
            }
            ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(com);
            da.Fill(ds);
            return ds;
        }
        catch (Exception ex)
        {
            return new DataSet();
            throw ex;
        }
        finally
        {
            com.Connection.Close();
        }
    }
    public static DataSet GETDATAPT(string ACTION, OTO_ENTITY oto)
    {
        SqlCommand com = new SqlCommand();
        DATABASE_CONTROL csdl = new DATABASE_CONTROL();
        DataSet ds;
        try
        {

            com.Connection = csdl.CheckConnect();
            com.Parameters.AddWithValue("ACTION", ACTION);
            if (oto != null)
            {
                com.Parameters.AddWithValue("MAXE", oto.MAXE);

            }
            com.CommandType = CommandType.StoredProcedure;
            com.CommandText = sp_Name;
            if (com.Connection.State == ConnectionState.Closed)
            {
                com.Connection.Open();
            }
            ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(com);
            da.Fill(ds);
            return ds;
        }
        catch (Exception ex)
        {
            return new DataSet();
            throw ex;
        }
        finally
        {
            com.Connection.Close();
        }
    }
    public static void UpdateDATAPT(string ACTION, OTO_ENTITY oto)
    {
        SqlCommand com = new SqlCommand();
        DATABASE_CONTROL csdl = new DATABASE_CONTROL();
        try
        {

            com.Connection = csdl.CheckConnect();
            com.Parameters.AddWithValue("ACTION", ACTION);
            if (oto != null)
            {
                com.Parameters.AddWithValue("MAXE", oto.MAXE);
                com.Parameters.AddWithValue("PHANTRAM", oto.MAXE);
            }
            com.CommandType = CommandType.StoredProcedure;
            com.CommandText = "UP_PHANTRAM";
            if (com.Connection.State == ConnectionState.Closed)
            {
                com.Connection.Open();
            }
            com.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            com.Connection.Close();
        }
    }
}